package com.sihai.ehr.model.biz;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.sihai.core.BaseEntity;
import com.sihai.ehr.model.sys.ExaminePeriodEnum;
import com.sihai.ehr.model.sys.Organization;

/**
 * 自定义薪资框架模型
 * 
 * @author henry
 * 
 */
@Entity
public class SalaryCustom extends BaseEntity<Long> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2587044232637867497L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	/** 组织结构ID */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "organization_id")
	private Organization organization;
	/** 方案名称 */
	private String projectTitle;
	/** 支付类型{0:单次发放,1:周期性发放} */
	private Integer paymentType;
	/** 周期发放类型　 */
	private ExaminePeriodEnum periodPayType;
	/** 开始时间：单次只有开始时间 */
	private Date startDate;
	/** 结束时间 */
	private Date endDate;
	/** 自定义框架计算表达式,%代表属性列在其中 */
	private String expression;

	@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "salaryCustom")
	private Set<SalaryCustomDetail> details = new HashSet<SalaryCustomDetail>();
	/** 已设定的人数 */
	private int employeeCount;

	@Override
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	public String getProjectTitle() {
		return projectTitle;
	}

	public void setProjectTitle(String projectTitle) {
		this.projectTitle = projectTitle;
	}

	public Integer getPaymentType() {
		return paymentType;
	}

	public void setPaymentType(Integer paymentType) {
		this.paymentType = paymentType;
	}

	public ExaminePeriodEnum getPeriodPayType() {
		return periodPayType;
	}

	public void setPeriodPayType(ExaminePeriodEnum periodPayType) {
		this.periodPayType = periodPayType;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public String getExpression() {
		return expression;
	}

	public void setExpression(String expression) {
		this.expression = expression;
	}

	public Set<SalaryCustomDetail> getDetails() {
		return details;
	}

	public void setDetails(Set<SalaryCustomDetail> details) {
		this.details = details;
	}
	
	public int getEmployeeCount() {
		return employeeCount;
	}
	
	public void setEmployeeCount(int employeeCount) {
		this.employeeCount = employeeCount;
	}

	/**
	 * 该方法用于向对象中加对象子集项
	 * 
	 * @param structureDetail
	 */
	public void addDetailItem(SalaryCustomDetail customDetail) {
		customDetail.setSalaryCustom(this); // 用关系维护端来维护关系
		this.details.add(customDetail);
	}
}
